<template>
    <div>
        <h1>会员增加</h1>
        <table class="table table-bordered">
            <tr>
                <td>姓名</td>
                <td>
                    <input type="text" v-model="state.name">
                </td>
            </tr>

            <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="state.pwd">
                </td>
            </tr>

            <tr>
                <td>确认密码</td>
                <td>
                    <input type="password" v-model="Qpwd">
                </td>
            </tr>

            <tr>
                <td>手机号</td>
                <td>
                    <input type="text" v-model="state.phone">
                </td>
            </tr>

            <tr>
                <td>邮件</td>
                <td>
                    <input type="text" v-model="state.email">
                </td>
            </tr>

            <tr>
                <td>身份证号</td>
                <td>
                    <input type="text" v-model="state.card">
                </td>
            </tr>

            <tr>
                <td>性别</td>
                <td>
                    <input type="radio" name="sesx" v-model="state.sex" :value="1">男
                    <input type="radio" name="sesx" v-model="state.sex" :value="2">女
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="button" value="提交" @click="add">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, toRefs } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';

let router = useRouter();
let route = useRoute();

let data: any = reactive({
    state: {
        "name": "",
        "pwd": "",
        "phone": "",
        "email": "",
        "card": "",
        "sex": 1,
    },
    Qpwd: "",
});

let { state, Qpwd } = toRefs(data);

const add = () => {
    let obj = {
        "id": route.query.id,
        "name": state.value.name,
        "pwd": state.value.pwd,
        "phone": state.value.phone,
        "email": state.value.email,
        "card": state.value.card,
        "sex": state.value.sex,
    };
    axios({
        url: '/api/Member/UpdateMember',
        method: 'put',
        data: obj
    }).then((res) => {
        if (res.data.data == -1) {
            alert("用户名已存在");
            return;
        } else if (res.data.data == -2) {
            alert("手机号已存在");
            return;
        }
        else {
            alert("修改成功");
            router.push("/list");
        }
    })

}
onMounted(() => {
    GetData();
})
const GetData = () => {
    let obj = {
        "id": route.query.id,
    };
    axios({
        url: '/api/Member/FanTian',
        method: 'get',
        params: obj
    }).then((res) => {
        state.value = res.data.data;
    })

}
</script>

<style scoped></style>